package com.ctshk.common.enums.appUser;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.starvip.enums
 * @Author: hef
 * @CreateTime: 2021-04-14 11:12
 * @Description: 交易类型
 */
@Getter
@AllArgsConstructor
public enum TransactionType {

    ADD(1, "增加积分","ACCRUAL", "应计"),

    MINUS(2,"扣减积分","REDEMPTION","偿还"),
    ;

    private Integer code;
    private String name;
    private String starVipCode;
    private String starVipName;

    public static String getStarVipCodeByCode(Integer code) {
        if(code == null) {
            return null;
        }
        TransactionType[] values = TransactionType.values();
        for (TransactionType value : values) {
            if(value.getCode().equals(code)) {
                return value.getStarVipCode();
            }
        }
        return null;
    }

    public static Integer getCodeByStarVipCode(String starVipCode) {
        if(StringUtils.isBlank(starVipCode)) {
            return null;
        }
        TransactionType[] values = TransactionType.values();
        for (TransactionType value : values) {
            if(value.getStarVipCode().equals(starVipCode)) {
                return value.getCode();
            }
        }
        return null;
    }

}
